//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.dstz.bpm.engine.action.handler.instance;

import com.dstz.base.core.util.StringUtil;
import com.dstz.bpm.act.service.ActInstanceService;
import com.dstz.bpm.api.constant.ActionType;
import com.dstz.bpm.api.constant.InstanceStatus;
import com.dstz.bpm.api.constant.NodeType;
import com.dstz.bpm.api.model.nodedef.BpmNodeDef;
import com.dstz.bpm.api.service.BpmProcessDefService;
import com.dstz.bpm.core.manager.BpmInstanceManager;
import com.dstz.bpm.core.model.BpmInstance;
import com.dstz.bpm.engine.action.cmd.DefaultInstanceActionCmd;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class InstanceStartActionHandler extends InstanceSaveActionHandler {
   @Resource
   BpmInstanceManager f;
   @Resource
   ActInstanceService i;
   @Resource
   BpmProcessDefService a;

   public InstanceStartActionHandler() {
   }

   @Override
   public void b(DefaultInstanceActionCmd startActionModel) {
      String destination = startActionModel.getDestination();
      BpmInstance instance = (BpmInstance)startActionModel.getBpmInstance();
      instance.setStatus(InstanceStatus.STATUS_RUNNING.getKey());
      String actInstId = null;
      if (StringUtil.isEmpty(destination)) {
         actInstId = this.i.startProcessInstance(instance.getActDefId(), instance.getBizKey(), startActionModel.getActionVariables());
      } else {
         actInstId = this.i.startProcessInstance(instance.getActDefId(), instance.getBizKey(), startActionModel.getActionVariables(), new String[]{destination});
      }

      instance.setActInstId(actInstId);
      this.f(startActionModel);
   }

   @Override
   protected void e(DefaultInstanceActionCmd actionModel) {
   }

   @Override
   public int getSn() {
      return 1;
   }

   @Override
   public ActionType getActionType() {
      return ActionType.START;
   }

   @Override
   public Boolean isSupport(BpmNodeDef nodeDef) {
      return nodeDef.getType() == NodeType.START;
   }
}
